﻿using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Web企业级开发
{
    public class Startup
    {
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        //把服务添加进容器
        public void ConfigureServices(IServiceCollection services)
        {
            //声明 引用哪些服务 
            services.AddControllersWithViews();//新增该行代码，为程序注入MVC服务
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        //配置请求规则（开发人员制定）
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            // 测试git
            //      是否开发环境 如果是
            if (env.IsDevelopment())
            {
                //启用 异常信息页  系统安全
                app.UseDeveloperExceptionPage();
            }

            // 启用路由 程序员 配置规则
            app.UseRouting();

            //启用终结点
            app.UseEndpoints(endpoints =>
            {

                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");

                endpoints.MapControllerRoute(
                    name: "soft",
                    pattern: "soft/{controller=Test}/{action=Index}/{id?}"
                    );

            });
        }

        string buildWelcomeString()
        {

            var date = DateTime.Now;
            var hour = date.Hour;

            var dateStr = date.ToString("yyyy年M月d日 HH时mm分");
            var timeRange = "";
            if (hour < 12)
            {
                timeRange = "早上好";
            }
            else if (hour < 15)
            {
                timeRange = "中午好";
            }
            else
            {
                timeRange = "晚上好";
            }

            return $"{timeRange}，当前时间是{dateStr}";
        }


    }


    class Student
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public string Class { get; set; }
        public DateTime Birthday { get; set; }
        public string NativePlace { get; set; }
        public Student()
        {

        }
        public Student(string id, string name, string stuClass, DateTime birthday, string nativePlace)
        {
            Id = id;
            Name = name;
            Class = stuClass;
            Birthday = birthday;
            NativePlace = nativePlace;
        }

        public string Say()
        {
            DateTime today = DateTime.Today;

            int age = Math.Abs((today.Year - Birthday.Year));
            if (Birthday.Day > today.Day)
            {
                age--;
            }
            return $"大家好, 我是来自{NativePlace}的{Name}, 我的学号是{Id}, 我今年{age}岁";
        }
    }



}
